package com.artislong.text2sql;

import jakarta.persistence.EntityManager;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author 陈敏
 * @version SqlExecutor.java, v 1.0 2025 07 02 23:18 chenmin Exp $
 * Created on 2025 07 02
 */
@Service
@AllArgsConstructor
public class SqlExecutor {

    private final EntityManager entityManager;

    public List<?> execute(String query) {
        List<?> result = entityManager
                .createNativeQuery(query)
                .getResultList();
        if (result.isEmpty()) {
            throw new RuntimeException("No results found for the provided query.");
        }
        return result;
    }
}
